package com.tomorrow.runner.util;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;

import java.util.List;

import cn.sucun.android.log.Log;

/**
 * 传感器工具类
 * Created by tomorrow on 16-5-1.
 */
public class SensorUtil {

    private static final String TAG = "SensorUtil";

    public static boolean isSupportSensor(Context context, int sensorType){
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        return sensorManager.getDefaultSensor(sensorType) != null;
    }

    public static void showSensorList(Context context) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        StringBuilder info = new StringBuilder();
        for (Sensor s : sensorList) {
            switch (s.getType()) {
                case Sensor.TYPE_ACCELEROMETER:
                    info.append("加速度传感器\n").append(s.getVersion()).append("\n")
                            .append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_AMBIENT_TEMPERATURE:
                    info.append("温度传感器\n").append(s.getVersion()).append("\n")
                            .append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_GRAVITY:
                    info.append("重力传感器\n").append(s.getVersion()).append("\n")
                            .append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_GYROSCOPE:
                    info.append("陀螺仪传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
                    info.append("无定标陀螺仪传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_HEART_RATE:
                    info.append("心跳传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_LIGHT:
                    info.append("光线传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_LINEAR_ACCELERATION:
                    info.append("线性加速传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_MAGNETIC_FIELD:
                    info.append("磁场传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_ORIENTATION:
                    info.append("方向传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_PRESSURE:
                    info.append("压力传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_PROXIMITY:
                    info.append("距离传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");

                    break;
                case Sensor.TYPE_RELATIVE_HUMIDITY:
                    info.append("相对湿度传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_ROTATION_VECTOR:
                    info.append("旋转矢量传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_SIGNIFICANT_MOTION:
                    info.append("重大事件传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_STEP_COUNTER:
                    info.append("记步传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                case Sensor.TYPE_STEP_DETECTOR:
                    info.append("步伐探测传感器\n").append(s.getVersion()).append("\n").append(s.getVendor()).append("\n");
                    break;
                default:
                    break;
            }
        }
        Log.i(TAG, info.toString());
    }
}
